import api from './index';
import { axios } from '@/utils/request';

import {getBalance,connect} from "cheese-sdk"


/**
 *
 * @param type "walletconnect" | "metamask" | "huobiwallet" | "mathwallet" | "tokenpocket"
 * @param callback
 * @returns {Promise<any>}
 */
export function loginWal(type,callback){

  return new Promise((resolve, reject)=>{
    connect(type,(res)=>{
      if(callback) callback(res);
    }).then((data)=>{
      resolve(data);
    }).catch(err=>{
      reject(err);
    })
  })
}


export function getBalanceToken(address){
  return new Promise((resolve, reject)=>{
    getBalance(address).then((balance) => {
      resolve(balance)
    }).catch(err=>{
      reject(err);
    })
  })
}

/**
 * login func
 * parameter: {
 *     username: '',
 *     password: '',
 *     remember_me: true,
 *     captcha: '12345'
 * }
 * @param parameter
 * @returns {*}
 */
export function login(parameter) {
  return axios({
    url: '/auth/login',
    method: 'post',
    data: parameter
  });
}

export function getSmsCaptcha(parameter) {
  return axios({
    url: api.SendSms,
    method: 'post',
    data: parameter
  });
}

export function getInfo(token) {
  return axios({
    url: '/user/info',
    method: 'post',
    data: token
  });
}

export function getCurrentUserNav(token) {
  return axios({
    url: '/user/nav',
    method: 'post',
    data: token
  });
}

export function logout() {
  return axios({
    url: '/auth/logout',
    method: 'post',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  });
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step(parameter) {
  return axios({
    url: api.twoStepCode,
    method: 'post',
    data: parameter
  });
}
